package com.cn.wanxi.model;

public class ResultModel {
    private static Integer code;
    private static String msg;
    private static Integer count;
    private static Object data;
    private static ResultModel resultModel = null;

    /**
     * 单例模式前提条件：必须私有构造方法
     */
    private ResultModel() {

    }

//    private ResultModel(Integer code, String msg, Integer count, Object data) {
//
//        this.code = code;
//        this.msg = msg;
//        this.count = count;
//        this.data = data;
//
//    }

    private static void setData(Integer rcode, String rmsg, Integer rcount, Object rdata) {
        code = rcode;
        msg = rmsg;
        count = rcount;
        data = rdata;
    }

    private static ResultModel getResultModel(Integer code, String msg, Integer count, Object data) {
        if (resultModel == null) {
            resultModel = new ResultModel();
        }
        setData(code, msg, count, data);

        return resultModel;
    }

    /**
     * getInstance 单例模式
     * 单例模式的目的：让内存只开辟一次空间，其他时候直接调用
     * 重载：方法名相同，参数类型和个数不同
     * 只需要拿到分页数据
     *
     * @return
     */
    public static ResultModel getInstance(Object data) {
        return getResultModel(0, "", 0, data);
    }

    /**
     * 动态赋值时，需要拿到总条数和分页数据
     *
     * @param count
     * @param data
     * @return
     */
    public static ResultModel getInstance(Integer count, Object data) {
        return getResultModel(0, "", count, data);
    }

    /**
     * 更新（新增，修改，删除）返回影响的条数
     *
     * @param count
     * @return
     */
    public static ResultModel getInstance(Integer count) {
        return getResultModel(0, "", count, null);
    }

    /**
     * 只是单纯返回字符
     *
     * @param msg
     * @return
     */
    public static ResultModel getInstance(String msg) {
        return getResultModel(0, msg, 0, null);
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
